package ww;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] scores = new int[n][3];
        for (int i = 0; i < n; i++) {
            scores[i][0] = scanner.nextInt();
            scores[i][1] = scanner.nextInt();
            scores[i][2] = scanner.nextInt();
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {

                int chineseDiff = Math.abs(scores[i][0] - scores[j][0]);
                int mathDiff = Math.abs(scores[i][1] - scores[j][1]);
                int englishDiff = Math.abs(scores[i][2] - scores[j][2]);

                int totalDiff = Math.abs((scores[i][0] + scores[i][1] + scores[i][2]) - (scores[j][0] + scores[j][1] + scores[j][2]));
                if (chineseDiff <= 5 && mathDiff <= 5 && englishDiff <= 5 && totalDiff <= 10) {
                    count++;
                }
            }
        }
        System.out.println(count);
        scanner.close();
    }
}